<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .login{display: block;}
        .welcome{display: none;}
    </style>
</head>
<body>
    <h1>这是首页</h1>
    <p class="login">请<a href="login.html">登录</a>或<a href="register.html">注册</a></p>
    <div class="welcome">
        <p>欢迎尊贵的会员<span>xxx</span>，<em>注销</em></p>
        <p><a href="cart.html">去购物车</a></p>
    </div>
    <a href="list.html">去选购</a>
<script src="js/jquery.2.2.4.js"></script>
<script>
    // 初始获取本地存储的数据
    var userData = sessionStorage.getItem("userState");
    userData = userData ? JSON.parse(userData) : userData;

    // 判断本地的数据状态，是否为登录成功，显示对应信息
    if(userData && userData.state === 1){
        $(".login").hide();
        $(".welcome").show().find("span").text(userData.user);
    }

    // 点击注销，修改登录成功后的状态
    $(".welcome").find("em").click(function(){
        // userData.state = 0;
        // sessionStorage.setItem("userState",JSON.stringify(userData));
        sessionStorage.removeItem("userState");
        location.reload();
    })

</script>
</body>
</html>